package NewCode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author wangchenghao
 * @date 2021/7/22
 **/
public class NC106 {
    public long solve(int[] A) {
        // write code here
        List<Integer> arr = new ArrayList<>();
        for (int i : A) {
            arr.add(i);
        }
        Collections.sort(arr);
        int length = arr.size();
        int max1 = length - 1;
        int max2 = length - 2;
        int max3 = length - 3;
        int min1 = 0;
        int min2 = 1;
        //最大值可能是最后三个正数之积；
        int result1 = arr.get(max1) * arr.get(max2) * arr.get(max3);
        //也可能是最小的两个负数之积乘以最大负数之积
        int result2 = arr.get(min1) * arr.get(min2);
        return Math.max(result1, result2);
    }

}
